import 'package:flutter/material.dart';
import 'package:flutter_demo/start_up/function_widgets/alerts/0x00_aleret_item.dart';

class CustomDialogPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {





    ////////////////////////////////////////////////////////////////////////

    Widget _buildMaterialDialogTransitions(
      BuildContext context,
      Animation<double> animation, 
      Animation<double> seecondaryAnimation,
      Widget child) {
      
      return ScaleTransition(
        scale: CurvedAnimation(
          parent: animation,
          curve: Curves.easeOut
        ),
        child: child,
      );
    }

    Future<T> showCustomDialog<T>({
      bool barrierDismissble = false,
      WidgetBuilder builder
    }) {
      final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
      return showGeneralDialog(
        context: context,
        pageBuilder: (buildContext, animation, secondaryAnimation) {
          final Widget pageChild = Builder(
            builder: builder,
          );
          return SafeArea(
            child: Builder(
              builder: (context) {
                return theme != null ? Theme(data: theme, child: pageChild) : pageChild;
              },
            ),
          );
        },
        barrierDismissible: barrierDismissble,
        barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
        barrierColor: Colors.black87,
        transitionDuration: const Duration(milliseconds: 150),
        transitionBuilder: _buildMaterialDialogTransitions
      );
    }

    void _showCustomDialog() async {
      await showCustomDialog<bool>(
        builder: (context) {
          return AlertDialog(
            title: Text("Tips"),
            content: Text("Are you suree remove this file?"),
            actions: <Widget>[
              FlatButton(
                child: Text("Cancel"),
                onPressed: () => Navigator.of(context).pop(false),
              ),
              FlatButton(
                child: Text("Delete"),
                onPressed: () => Navigator.of(context).pop(true),
              )
            ],
          );
        },
      );
    }







    return Scaffold(
      appBar: AppBar(
        title: Text("Custom alert"),
      ),
      body: Padding(
        padding: EdgeInsets.only(
          top: 18,
          bottom: 18
        ),
        child: ListView(
          children: <Widget>[
            AlertItem("Custom Alert", _showCustomDialog)
          ],
        ),
      ),
    );
  }
}